<?php

namespace App\Modules\Apicrzs\Http\Controllers;

use App\Modules\Apicrzs\Services\UserScoreService;
use App\Traits\CryptAES;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ScoreController extends BaseApicrzsController
{

    public function __construct(UserScoreService $authService)
    {
//        $token =  \request()->header('token');
//        $user_info = CryptAES::decryptToken($token,'user_grzq');
//        $this->user_id = $user_info['data']['user_id'];
        $this->service = $authService;
    }


    // 昨天、月、年 统计
    public function lists(Request $request): JsonResponse
    {
        $params = $request->all();
        $result = $this->service->lists($params);

        return $this->sendApiSuccess($result, $this->service->getError());
    }
    // 昨天 水机 积分统计
    public function getUserApparatusScoreList(Request $request): JsonResponse
    {
        $params = $request->all();
        $result = $this->service->getUserApparatusScoreList($params);
        return $this->sendApiSuccess($result, $this->service->getError());
    }
    // 累计积分
    public function getAccumulateScoreList(Request $request): JsonResponse
    {
        $params = $request->all();
        $result = $this->service->getAccumulateScoreList($params);
        return $this->sendApiSuccess($result, $this->service->getError());
    }
    // 我的 统计
    public function getCountSum(Request $request): JsonResponse
    {
        $params = $request->all();
        $result = $this->service->getCountSum($params);
        return $this->sendApiSuccess($result, $this->service->getError());
    }
    // 我的 统计
    public function statistics(Request $request): JsonResponse
    {
        $params = $request->all();
        $result = $this->service->statistics($params);
        return $this->sendApiSuccess($result, $this->service->getError());
    }

    /**
     * @param Request $request
     * @return JsonResponse
     */
    public function take(Request $request): JsonResponse
    {
        $params = $request->all();
        if ($result = $this->service->take($params)) {
            return $this->sendApiSuccess($result, $this->service->getError());
        }else{
            return $this->sendApiError($this->service->getError());
        }
    }

    /**
     * 已提现
     * @param Request $request
     * @return JsonResponse
     */
    public function usable(Request $request): JsonResponse
    {
        $params = $request->all();
        $params['user_id'] = $this->user_id;
        if ($result = $this->service->usableBalance($params)) {
            return $this->sendApiSuccess($result, $this->service->getError());
        }else{
            return $this->sendApiError($this->service->getError());
        }
    }

}
